{% extends "base.html" %}

{% block head %}
    <script src="{{ url_for('static',filename='js/register.js') }}"></script>
    <script>
        function validateEmail() {
            const email = document.getElementById("email").value;
            const error = document.getElementById("error");
            {#const email = $("#email").val();#}
            {#const error = $("#error").val();#}

            // 正则表达式验证邮件地址是否符合标准
            const emailRegex = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
            if (!emailRegex.test(email)) {
                error.innerHTML = "请输入有效的邮件地址";
                return false;
            }

            // 验证邮件地址是否为空
            if (email == "") {
                error.innerHTML = "邮件地址不能为空";
                return false;
            }

            // 验证通过，清空错误提示信息
            error.innerHTML = "";
            return true;
        }
    </script>
{% endblock %}

{% block title %}
    知了问答平台-注册
{% endblock %}

{% block body %}
    <div class="row mt-4">
        <div class="col"></div>
        <div class="col">
            <form method="POST">
                <div id="error"></div>
                <div class="form-group">
                    <label for="exampleInputEmail1">邮箱</label>

                    <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp"
                           name="email" required>

                    <small id="emailHelp" class="form-text text-muted">我们不会把邮箱用于其他用户</small>
                </div>
                <div class="form-group">
                    <label for="exampleInputEmail1">验证码</label>
                    <div class="input-group">
                        <input type="text" class="form-control" name="captcha">

                        <div class="input-group-append">

                            <button class="btn btn-outline-secondary" type="button" id="captcha-btn">获取验证码
                            </button>

                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label for="exampleInputEmail1">用户名</label>
                    <input type="text" class="form-control" name="username">
                </div>
                <div class="form-group">
                    <label for="exampleInputPassword1">密码</label>
                    <input type="password" class="form-control" id="exampleInputPassword1" name="password">
                </div>
                <div class="form-group">
                    <label for="exampleInputPassword1">确认密码</label>
                    <input type="password" class="form-control" name="password_confirm">
                </div>
                <button type="submit" class="btn btn-primary btn-block">立即注册</button>
            </form>
        </div>
        <div class="col"></div>
    </div>
{% endblock %}